package com.niuwa.p2p.service.impl.channel;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.niuwa.p2p.core.mvc.entity.PageBean;
import com.niuwa.p2p.dao.channel.ChannelVedioDao;
import com.niuwa.p2p.entity.PageQuery;
import com.niuwa.p2p.entity.channel.ChannelVedio;
import com.niuwa.p2p.entity.user.User;
import com.niuwa.p2p.service.channel.IChannelImgVideoService;
import com.niuwa.p2p.vo.channel.ChannelVideoNwFileVo;

@Service
public class ChannelImgVideoImpl implements IChannelImgVideoService {
	@Autowired
	private ChannelVedioDao channelVedioDao;

	/**
	 * 分页查询影像文件列表
	 */
	@Override
	public PageBean<ChannelVideoNwFileVo> searchChannelImgVideoRecord(
			Map<String, Object> paramMap) {
		// 执行查询操作
		PageBean<ChannelVideoNwFileVo> page = new PageBean<ChannelVideoNwFileVo>();
		if (paramMap.get("corpCode") != "") {
			// 总条数
			int totalCount = channelVedioDao
					.getChannelImgVideoCountByCorpCode(paramMap);
			page = new PageBean<ChannelVideoNwFileVo>(totalCount);
			// 当前页
			page.setPage(((PageQuery) paramMap.get(PageQuery.PAGEQUERY))
					.getPage());
			page.setRows(channelVedioDao
					.searchChannelImgVideoByCorpCode(paramMap));
		} else {
			page.setTotal(0);
			page.setRows("");
		}
		return page;
	}

	/**
	 * 假删除影像文件的本地记录
	 * 
	 * @param fileID
	 */
	@Override
	public void deleteImgVideo(String fileID, String corpCode) {
		ChannelVedio channelVedio = new ChannelVedio();
		channelVedio.setFileID(fileID);
		channelVedio.setCorpCode(corpCode);
		channelVedio.setDelFlag("Y");
		channelVedioDao.updateByPrimaryKeySelective(channelVedio);
	}

	/**
	 * 保存影像文件到数据库
	 * 
	 * @param channelVideo
	 */
	@Override
	public void saveImgVideo(String fileID, String corpCode, User user) {
		ChannelVedio channelVideo = new ChannelVedio();
		channelVideo.setCorpCode(corpCode);
		channelVideo.setFileID(fileID);
		channelVideo.setOperator(user.getId());
		channelVideo.setOperatorName(user.getUserName());
		channelVideo.setDelFlag("N");
		channelVedioDao.insert(channelVideo);
	}

}
